function(ob_unittest case)
  if(ARGC EQUAL 1)
    add_executable(${case} ${case}.cpp)
  else()
    add_executable(${ARGV})
  endif()
  if (case MATCHES "^test_.*")
    add_test(${case} ${case})
    set_tests_properties(${case} PROPERTIES TIMEOUT 300)
  endif()
  target_link_libraries(${case} PRIVATE oceanbase gtest gmock)
  target_include_directories(${case}
    PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/unittest ${CMAKE_SOURCE_DIR}/mittest ${CMAKE_SOURCE_DIR}/deps/oblib/unittest)
endfunction()

file(COPY . DESTINATION . FILES_MATCHING PATTERN "*.test")
file(COPY . DESTINATION . FILES_MATCHING PATTERN "*.sql")
file(COPY . DESTINATION . FILES_MATCHING PATTERN "*.result")
file(COPY . DESTINATION . FILES_MATCHING PATTERN "*.schema")
file(COPY run_tests.sh DESTINATION .)

add_subdirectory(sql)
add_subdirectory(libobcdc)
add_subdirectory(backup)
add_subdirectory(archive)
add_subdirectory(logservice)
add_subdirectory(storage)
add_subdirectory(observer)
add_subdirectory(share)
add_subdirectory(rootserver)
add_subdirectory(tools)
add_subdirectory(data_dictionary)
